<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
	<meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <link rel="shortcut icon" href="../images/favicon.ico">
    <link rel="apple-touch-icon-precomposed" href="../images/apple-touch-icon.png">
	<title>exmobi-camera</title>
	<link rel="stylesheet" href="../../dist/seedsui.min.css">
	<style type="text/css">
	/*关闭按钮*/
	.card .close{
		position:absolute;
		top:-4px;
		right:-4px;
	}
	/*=========== 图片上传 ===========*/
    .app-grid-photo li{
	    padding: 6px;
	}
	.app-grid-photo .grid-icon{
	    height: 70px;
	    width: 100%;
	    border:1px solid #e5e5e5;
	    background-color: white;
	    background-size: cover;
	    color: #e5e5e5;
	}
	.app-grid-photo .close{
	    position: absolute;
	    top:-4px;
	    right:-4px;
	}
	.app-grid-photo .icon{
	    pointer-events:none;
	}
	</style>
</head>

<body ontouchstart="">
		<header>
			<div class="titlebar">
		        <a href="javascript:Exmobi.close()"><i class="icon icon-arrowleft"></i></a>
		        <h1 class="titlebar-title">照片选择</h1>
		    </div>
		</header>
		<article>
			<a class="button block" style="margin:8px;" href="javascript:Exmobi.album()">调用系统相册</a>
			<a class="button block info" style="margin:8px;" href="javascript:Exmobi.imageChoice(500,5)">相册选择</a>
			<a class="button block success" style="margin:8px;" href="javascript:Exmobi.camera()">拍照上传</a>
			<p class="sliver">图片列表</p>
			<ul id="imagelist" class="grid app-grid-photo" data-col="4">
				<li>
					<a class="grid-icon" style="background-image: url(../images/1.jpg)"></a>
				</li>
				<li>
					<a class="grid-icon" style="background-image: url(../images/2.jpg)"></a>
				</li>
				<li>
					<a class="grid-icon" href="javascript:Exmobi.camera()">
						<i class="icon icon-plus size50"></i>
					</a>
				</li>
			</ul>
		</article>

    <script src="../../dist/seedsui.min.js"></script>
    <!--Exmobi能力-->
    <!--<script src="../scripts/lib/exmobi/exmobi.js"></script>-->
	<script>
		//生成选择图片字符串
		function getImgText(path){
			var li=document.createElement("li");
			var a=document.createElement("a");
			a.setAttribute("style","background-image: url("+path+")");
			var span=document.createElement("span");
			span.setAttribute("class","close");
			var i=document.createElement("i");
			i.setAttribute("class","icon icon-close");
			i.setAttribute("onclick","removeCell(this)");
			span.appendChild(i);
			a.appendChild(span);
			li.appendChild(a);
			return li;
			/*return '<li><a style="background-image: url('+path+')"><span class="close"><i class="icon icon-close" onclick="removeCell(this)"></i></span></a></li>';*/
		}
		var imagelist=document.getElementById("imagelist");
		//相册选择
		function imageChoiceCallback(selectPaths){
			var selectPaths = this.getFilePaths();//获取照片列表
			for(var i=0;i<selectPaths.length;i++){
				var url = selectPaths[i];
				var selectImg=getImgText(url);
				imagelist.parentNode.insertBefore(selectImg,imagelist.childNodes[0]);
			}
			
			//$("#imagelist").prepend(selectImgs);
		}
		//拍照
		function cameraCallback(){
			var selectImg=getImgText(this.value);//获得拍照返回的路径
			imagelist.parentNode.insertBefore(selectImg,imagelist.childNodes[0]);
			//$("#imagelist").prepend(selectImg);
		}
		//调用系统相册
		function albumCallback(path){
			var selectImg=getImgText(path);
			imagelist.parentNode.insertBefore(selectImg,imagelist.childNodes[0]);
			//$("#imagelist").prepend(selectImg);
		}
		//移除grid-cell
		function removeCell(thisobj){
			var img=thisobj.parentNode.parentNode.parentNode;
			img.parentNode.removeChild(img);
			//$(thisobj).parent().parent().parent().remove();
		}
		//定义exmobi返回
		function back(){Exmobi.close();}
	</script>
</body>
</html>